package com.yuandian.management.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.management.entity.ConfComponentResource;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.bpm.common.log.annotation.SysLog;
import com.yuandian.management.service.ConfComponentResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 组件资源配置表-Controller
 * @author zfsn
 * @date 2023-3-17
 */
@Api(tags = "IT路径图组件")
@RestController
@RequestMapping("/componentResource")
public class ConfComponentResourceController {

	@Autowired
	private ConfComponentResourceService confComponentResourceService;

	/**
	 * 通过主键查询数据
	 * @param idList 主键集合
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键查询数据", notes = "通过主键查询数据，支持批量查询")
	@GetMapping("/{ids}")
	public R<List<ConfComponentResource>> queryByIds(@PathVariable("ids") List<Integer> idList) {
		return R.ok(confComponentResourceService.listByIds(idList));
	}

	/**
	 * 分页查询
	 * @param confComponentResource 筛选条件
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@PostMapping
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", value = "所属系统id", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "segmentId", value = "所属网端id", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "pageSize", value = "每页大小", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "pageNum", value = "当前页数", paramType = "body", required = true, dataTypeClass = Integer.class),
	})
	public R<Page<ConfComponentResource>> listPage(@RequestBody @ApiIgnore ConfComponentResource confComponentResource) {
		return R.ok(confComponentResourceService.listPage(confComponentResource));
	}

	/**
	 * 新增数据
	 * @param confComponentResource 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "新增数据", notes = "新增数据")
	@PostMapping("/save")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", value = "所属系统id", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "segmentId", value = "所属网端id", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "identifyStr", value = "资源串", paramType = "body", required = true, dataTypeClass = String.class),
	})
	public R<String> saveData(@RequestBody @ApiIgnore ConfComponentResource confComponentResource) {
		return confComponentResourceService.saveData(confComponentResource);
	}

	/**
	 * 通过主键更新数据
	 * @param confComponentResource 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键更新数据", notes = "通过主键更新数据")
	@PutMapping
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "id", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "systemId", value = "所属系统id", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "segmentId", value = "所属网端id", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "identifyStr", value = "资源串", paramType = "body", required = true, dataTypeClass = String.class),
	})
	public R<String> updateData(@RequestBody @ApiIgnore ConfComponentResource confComponentResource) {
		return confComponentResourceService.updateData(confComponentResource);
	}

	/**
	 * 通过主键删除数据
	 * @param ids 主键
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键删除数据", notes = "通过主键删除数据")
	@SysLog("删除组件资源配置表数据")
	@DeleteMapping("/delete/{ids}")
	public R<String> removeByIds(@PathVariable("ids") List<Integer> ids){
		return confComponentResourceService.deleteByIds(ids);
	}

}